home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 10828 / 10828.xpi / chrome / content / thumbnails-min.js < prev    next >
Text File  |  2009-11-01  |  12KB  |  1 lines

  1. var ntkThumbs={currentPriorityScheduleURL:"",currentFilename:"",ioService:null,URLsArr:new Array(),FilenamesArr:new Array(),thumbFolder:"thumbnails",thumbnailImageWidth:179,thumbnailImageHeight:136,init:function(){},unregisterBackgroundLoader:function(){var a=document.getElementById("ntkLoaderBrowser");if(a){try{a.removeEventListener("pageshow",ntkBackgroundBrowserListener,true);a.removeEventListener("pagehide",ntkBackgroundBrowserListener,true);a.removeEventListener("load",ntkBackgroundBrowserListener,true);a.removeEventListener("unload",ntkBackgroundBrowserListener,true);a.removeEventListener("beforeunload",ntkBackgroundBrowserListener,true);a.removeEventListener("DOMSubtreeModified",ntkBackgroundBrowserListener,true);a.removeEventListener("DOMLinkAdded",ntkBackgroundBrowserListener,true);a.removeEventListener("DOMContentLoaded",ntkBackgroundBrowserListener,true);if(a.contentDocument){a.contentDocument.removeEventListener("DOMContentLoaded",ntkBackgroundBrowserListener,true)}}catch(b){alert("yo")}}},startBackgroundLoad:function(f,h){if(h.length==0||h.length!=f.length){return}var c,d,i;var b=document.createElement("hbox");b.setAttribute("id","ntkLoaderBox");b.setAttribute("style","overflow: hidden; visibility: hidden;");b.setAttribute("flex","1");b.setAttribute("height","0");b.setAttribute("maxheight","0");b.setAttribute("minheight","0");var e=document.createElement("vbox");e.setAttribute("id","ntkLoaderSubBox");e.setAttribute("id","ntkLoaderSubBox");e.setAttribute("flex","0");b.appendChild(e);document.documentElement.appendChild(b);ntkThumbs.currentFilename=h.shift();i=f.shift();ntkThumbs.URLsArr=f;ntkThumbs.FilenamesArr=h;var k;k=document.createElement("iframe");k.setAttribute("class","ntkBrowser");k.setAttribute("type","content");k.setAttribute("disablehistory","true");k.setAttribute("flex","1");k.setAttribute("id","ntkLoaderBrowser");var j="800";var a="600";var g=document.getElementById("ntkLoaderSubBox");if(g.firstChild){ntkThumbs.unregisterBackgroundLoader();g.replaceChild(k,g.firstChild)}else{g.appendChild(k)}k.addEventListener("pageshow",ntkBackgroundBrowserListener,true);k.addEventListener("pagehide",ntkBackgroundBrowserListener,true);k.addEventListener("load",ntkBackgroundBrowserListener,true);k.addEventListener("unload",ntkBackgroundBrowserListener,true);k.addEventListener("beforeunload",ntkBackgroundBrowserListener,true);k.addEventListener("DOMSubtreeModified",ntkBackgroundBrowserListener,true);k.addEventListener("DOMLinkAdded",ntkBackgroundBrowserListener,true);k.addEventListener("DOMContentLoaded",ntkBackgroundBrowserListener,true);if(k.contentDocument){k.contentDocument.addEventListener("DOMContentLoaded",ntkBackgroundBrowserListener,true)}ntkBackgroundBrowserListener.startTime=(new Date()).getTime();ntkBackgroundBrowserListener.captureStarted();k.docShell.allowAuth=false;k.docShell.allowJavascript=false;k.docShell.allowPlugins=false;k.mIconURL=null;g.setAttribute("width",j);g.setAttribute("minwidth",j);g.setAttribute("maxwidth",j);g.setAttribute("height",a);g.setAttribute("minheight",a);g.setAttribute("maxheight",a);g.style.width=j+"px !important";g.style.maxWidth=g.style.width;g.style.minWidth=g.style.width;g.style.height=a+"px !important";g.style.maxHeight=g.style.height;g.style.minHeight=g.style.height;i=i.replace("/s+/g","");ntkThumbs.currentPriorityScheduleURL=i;k.setAttribute("src",i)},backgroundLoadFinished:function(a){var h=document.getElementById("ntkLoaderBrowser");try{var f=Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);var j=f.newURI(h.contentDocument.documentURI,h.contentDocument.characterSet,null);var d=ntkThumbs.currentPriorityScheduleURL;var g=null;var c=null;d=d.replace("/s+/g","");if(d==ntkThumbs.currentPriorityScheduleURL){if((j.spec.substr(0,"about:neterror".length)=="about:neterror")||((j.spec.substr(0,"about:blank".length)=="about:blank")&&(d!="about:blank"))){}else{ntkThumbs.saveSnapshot(h)}}}catch(b){}if(ntkThumbs.URLsArr.length==0){var i=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.ntk.");i.setBoolPref("thumbsDone",true)}ntkThumbs.startBackgroundLoad(ntkThumbs.URLsArr,ntkThumbs.FilenamesArr)},verifyNtkThumbFolder:function(){var a="{FC5BAC7D-D696-4ba6-B913-CF8F000C33DF}";var c=Components.classes["@mozilla.org/extensions/manager;1"].getService(Components.interfaces.nsIExtensionManager);var b=c.getInstallLocation(a).getItemFile(a,"chrome/content");b.append(ntkThumbs.thumbFolder);if(!b.exists()||!b.isDirectory()){b.create(Components.interfaces.nsIFile.DIRECTORY_TYPE,493)}},removeThumbnailImage:function(c){var b="{FC5BAC7D-D696-4ba6-B913-CF8F000C33DF}";var f=Components.classes["@mozilla.org/extensions/manager;1"].getService(Components.interfaces.nsIExtensionManager);var d=f.getInstallLocation(b).getItemFile(b,"chrome/content");d.append(ntkThumbs.thumbFolder);if(d.exists()&&d.isDirectory()){var a=c;var i=d.directoryEntries;while(i.hasMoreElements()){var g=i.getNext().QueryInterface(Components.interfaces.nsIFile);if((g.isFile())&&(g.leafName.match(a))){try{g.remove(false)}catch(h){}}}}},fileExist:function(c){var b="{FC5BAC7D-D696-4ba6-B913-CF8F000C33DF}";var e=Components.classes["@mozilla.org/extensions/manager;1"].getService(Components.interfaces.nsIExtensionManager);var d=e.getInstallLocation(b).getItemFile(b,"chrome/content");d.append(ntkThumbs.thumbFolder);if(d.exists()&&d.isDirectory()){var a=c;var g=d.directoryEntries;while(g.hasMoreElements()){var f=g.getNext().QueryInterface(Components.interfaces.nsIFile);if((f.isFile())&&(f.leafName.match(a))){return true}}}return false},saveCanvas:function(d,j,k,f,c){var i=Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);var b="image/png";var e=d.toDataURL(b,"");var a=i.newURI(e,"UTF8",null);var h=i.newFileURI(j);var g=Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Components.interfaces.nsIWebBrowserPersist);g.persistFlags=Components.interfaces.nsIWebBrowserPersist.PERSIST_FLAGS_REPLACE_EXISTING_FILES;g.persistFlags|=Components.interfaces.nsIWebBrowserPersist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;g.progressListener={onProgressChange:function(n,l,p,q,o,m){},onStateChange:function(m,l,n,p){if(n&Components.interfaces.nsIWebProgressListener.STATE_STOP){var o=Components.classes["@mozilla.org/network/protocol;1?name=file"].createInstance(Components.interfaces.nsIFileProtocolHandler).getURLSpecFromFile(j)}}};g.saveURI(a,null,null,null,null,j)},saveSnapshot:function(k){var d=false;var j=null;var m;ntkThumbs.verifyNtkThumbFolder();if(k.contentDocument instanceof ImageDocument){d=true;m=k.contentDocument.imageRequest.decoderObserver}var f=179,o=136;var l=document.createElementNS("http://www.w3.org/1999/xhtml","canvas");var p=l.getContext("2d");if(d){l.width=800;l.height=800;p.drawImage(m,0,0,f,o)}else{var c=false;l.width=0.75*k.contentWindow.innerWidth;l.height=Math.floor((0.75*k.contentWindow.innerWidth/ntkThumbs.thumbnailImageWidth*ntkThumbs.thumbnailImageHeight));if(k.contentWindow.scrollY!=0){try{p.drawWindow(k.contentWindow,0,0,k.contentWindow.innerWidth,k.contentWindow.innerHeight+k.contentWindow.scrollMaxY,"rgb(255,255,255)")}catch(n){p.drawWindow(k.contentWindow,0,0,k.contentWindow.innerWidth,l.height*k.contentWindow.innerWidth/l.width,"rgb(255,255,255)")}}else{p.drawWindow(k.contentWindow,0,0,k.contentWindow.innerWidth,l.height*k.contentWindow.innerWidth/l.width,"rgb(255,255,255)")}if(c){p.restore()}else{var i=document.createElementNS("http://www.w3.org/1999/xhtml","canvas");i.width=f;i.height=o;p=i.getContext("2d");p.drawImage(l,0,0,l.width,l.height,0,0,i.width,i.height);l=i}}var b=(new Date()).getTime();var h="{FC5BAC7D-D696-4ba6-B913-CF8F000C33DF}";var a=Components.classes["@mozilla.org/extensions/manager;1"].getService(Components.interfaces.nsIExtensionManager);var g=a.getInstallLocation(h).getItemFile(h,"chrome/content");ntkThumbs.removeThumbnailImage(ntkThumbs.currentFilename);g.append(ntkThumbs.thumbFolder);g.append(ntkThumbs.currentFilename);ntkThumbs.saveCanvas(l,g,f,o,b)},};var ntkBackgroundBrowserListener={alreadyLoaded:false,firstLoadTime:-1,finishedTime:-1,startTime:-1,currentTimeoutId:-1,loadFinished:false,QueryInterface:function(a){if(a.equals(Components.interfaces.nsIDOMEventListener)||a.equals(Components.interfaces.nsIWebProgressListener)||a.equals(Components.interfaces.nsISupportsWeakReference)||a.equals(Components.interfaces.nsISupports)){return this}throw Components.results.NS_NOINTERFACE},handleEvent:function(c){if(ntkBackgroundBrowserListener.loadFinished){return}if((c.type=="load")||(c.type=="pageshow")){if(!ntkBackgroundBrowserListener.alreadyLoaded){if(c.currentTarget.contentDocument!=c.originalTarget){return}if(c.currentTarget.contentDocument.documentURI=="about:blank"){return}ntkBackgroundBrowserListener.alreadyLoaded=true;ntkBackgroundBrowserListener.firstLoadTime=(new Date()).getTime()}ntkBackgroundBrowserListener.resetTimer()}else{if(c.type=="unload"){if(c.currentTarget.contentDocument==c.originalTarget){ntkBackgroundBrowserListener.alreadyLoaded=false;if(ntkBackgroundBrowserListener.currentTimeoutId!=-1){clearTimeout(ntkBackgroundBrowserListener.currentTimeoutId)}ntkBackgroundBrowserListener.captureStarted()}else{ntkBackgroundBrowserListener.resetTimer()}}else{if(c.type=="DOMSubtreeModified"){if(ntkBackgroundBrowserListener.alreadyLoaded){ntkBackgroundBrowserListener.resetTimer()}}else{if(c.type=="DOMContentLoaded"){if(c.currentTarget instanceof HTMLDocument){var b=c.currentTarget.getElementsByTagName("input");for(var a=0;a<b.length;a++){b[a].wrappedJSObject.focus=function(){}}}}}}}c.stopPropagation()},resetTimer:function(){if(ntkBackgroundBrowserListener.currentTimeoutId!=-1){clearTimeout(ntkBackgroundBrowserListener.currentTimeoutId);ntkBackgroundBrowserListener.currentTimeoutId=-1}if(!ntkBackgroundBrowserListener.loadFinished){var a=(new Date()).getTime();if(a>(ntkBackgroundBrowserListener.startTime+20000)){ntkBackgroundBrowserListener.captureFinished()}else{ntkBackgroundBrowserListener.currentTimeoutId=setTimeout(ntkBackgroundBrowserListener.captureFinished,500)}}},checkTimeout:function(){},captureStarted:function(){ntkBackgroundBrowserListener.alreadyLoaded=false;ntkBackgroundBrowserListener.loadFinished=false;ntkBackgroundBrowserListener.firstLoadTime=(new Date()).getTime();if(ntkBackgroundBrowserListener.currentTimeoutId!=-1){clearTimeout(ntkBackgroundBrowserListener.currentTimeoutId);ntkBackgroundBrowserListener.currentTimeoutId=-1}var a=(new Date()).getTime();ntkBackgroundBrowserListener.currentTimeoutId=setTimeout(ntkBackgroundBrowserListener.resetTimer,20000-(a-ntkBackgroundBrowserListener.startTime))},captureFinished:function(){if(ntkBackgroundBrowserListener.loadFinished){return}ntkBackgroundBrowserListener.loadFinished=true;ntkBackgroundBrowserListener.finishedTime=(new Date()).getTime();ntkThumbs.backgroundLoadFinished()},onStateChange:function(d,b,e,f){if(ntkBackgroundBrowserListener.loadFinished){return}if(e&Components.interfaces.nsIWebProgressListener.STATE_START){if(e&Components.interfaces.nsIWebProgress.NOTIFY_STATE_IS_WINDOW){ntkBackgroundBrowserListener.alreadyLoaded=false;if(ntkBackgroundBrowserListener.currentTimeoutId!=-1){clearTimeout(ntkBackgroundBrowserListener.currentTimeoutId)}ntkBackgroundBrowserListener.captureStarted()}}if(e&Components.interfaces.nsIWebProgressListener.STATE_STOP){if(e&Components.interfaces.nsIWebProgressListener.STATE_IS_WINDOW){var a=document.getElementById("ntkLoaderBrowser");if(!ntkBackgroundBrowserListener.alreadyLoaded){if(a&&a.contentDocument&&((a.contentDocument.location.toString()!="about:blank")||(a.getAttribute("src")=="about:blank"))){ntkBackgroundBrowserListener.alreadyLoaded=true;ntkBackgroundBrowserListener.firstLoadTime=(new Date()).getTime()}}if(ntkBackgroundBrowserListener.alreadyLoaded){var c=false;if(a){if(a.contentDocument instanceof ImageDocument){c=true}}if(c){ntkBackgroundBrowserListener.captureFinished()}else{ntkBackgroundBrowserListener.resetTimer()}}}}return 0},onLocationChange:function(b,a,c){return 0},onProgressChange:function(){return 0},onStatusChange:function(){return 0},onSecurityChange:function(){return 0},onLinkIconAvailable:function(){return 0}};